<?php

namespace Maestros\Controller\Service;

use Zend\Db\Adapter\Adapter;
use Componentes\Controller\UtilsArrayController;
use Maestros\Model\Entity\MateriaEje;
use Maestros\Controller\Service\GenericService;
use Maestros\Model\Dao\MateriaEjeDao;

class MateriaEjeService extends GenericService {
    
     /**
     * @var Zend\Db\Adapter\Adapter 
     */
    private $dbAdapter;
    private static $materiaEjeService;

    /**
     * @param \Zend\Db\Adapter\Adapter $dbAdapter
     */
    private function __construct(Adapter $dbAdapter) {
        $this->dbAdapter = $dbAdapter;
    }

    public static function getInstance($adapter) {
        if (self::$materiaEjeService == null) {
            self::$materiaEjeService = new MateriaEjeService($adapter);
        }
        return self::$materiaEjeService;
    }

    public function getMateriaEjeDao() {
        return MateriaEjeDao::getInstance($this->dbAdapter);
    }

     public function getRegistro($id){
        $data = null;
        $success = false;
        $materiaEje = $this->obtenerMateriaEjeSegunId($id);
        if ($materiaEje->getId() != null) {
            $data[0] = $materiaEje->objectToArray();;
            $success = true;
            $mensaje = 'NivelMalla Encontrada';
        }
        $output = array(
            'success' => $success,
            'data' => $data,
            'total' => count($data)
        );
        return $output;
        
        
        
    }
    
    //------Retornan los objetos-------

    /**
     * Retorna un registro completo dado un id de malla de la tabla malla
     * @param $id type string
     * @return Objeto malla
     */
    public function obtenerMateriaEjeSegunId ($id){
        $registros = $this->getMateriaEjeDao()->getRegistro($id);
        $data = UtilsArrayController::llenarData($registros);
        $materiaEje = new MateriaEje($data[0]);
        $materiaEje->setId($data[0]['id']);
        $materiaEje->setDescripcion($data[0]['descripcion']);
        return $materiaEje;
        
        
    }
    //put your code here
}
